package com.zcc.makingfriend.service.impl;

import com.zcc.makingfriend.dao.Commented;
import com.zcc.makingfriend.mapper.CommentedMapper;
import com.zcc.makingfriend.service.CommentedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author zcc
 */
@Service
public class CommentedServiceImpl implements CommentedService {

    @Autowired
    CommentedMapper commentedMapper;


    @Override
    public int addCommented(Commented commented) {
        commented.setLikes(0L);
        commented.setStatus(0);
        commented.setCreated(LocalDateTime.now());
        commented.setCommented(0);
        return commentedMapper.addCommented(commented);
    }

    @Override
    public int deleteCommented(Long id) {
        return commentedMapper.deleteCommented(id);
    }

    @Override
    public int isLikeCommented(Long id, int isLike, Long likes) {
        if (isLike == 1) {
            isLike += 1;
        } else {
            isLike -= 1;
        }
        return commentedMapper.isLikeCommented(id, likes);
    }

    @Override
    public int reportCommented(Long id) {
        // 还需要处理举报后推送给谁的逻辑
        return commentedMapper.reportCommented(id);
    }

    @Override
    public List<Commented> findCommentedByCommentId(Long commentId) {
        List<Commented> commentedByCommentId = commentedMapper.findCommentedByCommentId(commentId);
        return commentedByCommentId;
    }
}
